import config from './config.js';

function uploadFile(filePath) {
	return new Promise(function(resolve, reject) {
		uni.uploadFile({
			url: `${config.reqUrl}/api/common/upload`,
			filePath,
			name: 'file',
			success: res => {
				console.log(JSON.parse(res.data), '上传文件成功');
				resolve({
					url: JSON.parse(res.data).data.url
				});
			},
			fail: err => {
				console.log(err, '上传文件失败');
				uni.showToast({
					title: '上传失败请重新上传',
					icon: 'none'
				})
				reject(err);
			}
		});
	});
}

export default uploadFile;